package com.fyzk.activity.prize;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;

import com.fyzk.dialog.DJ_ProgressDialog;
import com.fyzk.utils.DateUtils;
import com.tyjc.lottery.R;

abstract public class JC_PrizeBaseActivity extends BasePrizeHistoryActivity {

    protected String getTopTitle() {
        return "竞彩开奖";
    }

    @Override
    protected void init() {
        topTitleView.setCenterText(getTopTitle());
        jc_requestData();
    }

    @Override
    public void onRightClick() {
        showTimeChooseDialog();
    }

    public void jc_requestData() {
        DJ_ProgressDialog.show(getContext(), true, true);
    }

    @Override
    protected void getInfor(int id) {
    }

    /**
     * 时间选择器
     *
     * @return
     */
    private void showTimeChooseDialog() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_timechoose, null);
        final DatePicker picker = view.findViewById(R.id.timechoose_dp);
        String[] timeStrs = currDate.split("-");
        picker.updateDate(Integer.parseInt(timeStrs[0]), (Integer.parseInt(timeStrs[1])-1), Integer.parseInt(timeStrs[2]));
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle("日期选择");
        builder.setView(view);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                int month = picker.getMonth()+1;
                int day = picker.getDayOfMonth();

                currDate = picker.getYear()+"-"+(month < 10 ? "0"+month : month)+"-"+(day < 10 ? "0"+day : day);
                weekTime = DateUtils.dateToWeek(currDate);

                jc_requestData();
            }
        });
        builder.setNegativeButton("取消", null);
        builder.create().show();
    }

}
